home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / ca29_3.zip / XLATE.CMD < prev   
OS/2 REXX Batch file  |  1990-06-21  |  15KB  |  638 lines

  1. ; ----- COM-AND Edit transation tables
  2. ;
  3. ;    This script opens a window and allows the editing of translation
  4. ;    tables.  COM-AND supports two transations: incoming and outgoing.
  5. ;    The first 128 bytes of the incoming table are displayed on entry.
  6. ;
  7. ;    The incoming table is 256 entries.  The outgoing table is the same
  8. ;    size.  The 'n'th position represents the translation value for the
  9. ;    character with value 'n'.
  10. ;
  11. ;    Translation may be enabled here in this script - and in COM-AND's
  12. ;    Alt-V emulations.
  13. ;
  14. ;    R.McG, commenced 1/89
  15. ; ----- Usages -----------------
  16. ;    S19 -----> COM-AND.XLT file name to be used
  17. ;    S10-S17 -> The file loaded into memory
  18. ;    N99 -----> Display page (0,1,2,3)
  19. ;    FLAG(9) -> Hex/decimal switch
  20. ;    FLAG(8) -> Modification to file
  21. ; ------------------------------
  22. ;    Initialization
  23. ;
  24. ;* TRACE ON
  25.    ON ESCAPE GOSUB Exit         ; SAVE is performed in Window
  26.    LEGEND " Edit translations"
  27.    SET TTHRU OFF            ; Disallow typeahead
  28.    N99 = 0                ; Base of current window
  29.    SET FLAG(9) OFF            ; Hex/decimal flag (true = hex)
  30.    SET FLAG(8) OFF            ; Modification flag
  31. ;
  32. ;    Initialize, and paint an initial window
  33. ;
  34.    GOSUB Set_Fname            ; S19 -> target file
  35.    UPPER S19                ; .. make nice
  36.    GOSUB Load                ; Load values
  37.    GOSUB Window             ; Open the window
  38. ;
  39. ;    Main-loop - look for keyentry
  40. ;
  41. Main_Loop:
  42.    ATSAY  22,11 (default) "          "
  43.    LOCATE 22,11
  44.    KEYGET S0                ; Get a keystroke
  45. ;
  46. ;    Act upon the keystroke
  47. ;
  48.    SWITCH S0
  49.       CASE "4900"                       ; Pgup
  50.      GOTO PgUp
  51.       ENDCASE
  52.       CASE "5100"                       ; PgDn
  53.      GOTO PgDn
  54.       ENDCASE
  55.       CASE "4700"                       ; Home
  56.      GOTO Home
  57.       ENDCASE
  58.       CASE "4F00"                       ; End
  59.      GOTO End
  60.       ENDCASE
  61.       CASE "H"                          ; H)ex
  62.      SET FLAG(9) ON
  63.      GOSUB DISPPAGE
  64.      GOTO Main_Loop
  65.       ENDCASE
  66.       CASE "D"                          ; D)ecimal
  67.      SET FLAG(9) OFF
  68.      GOSUB DISPPAGE
  69.      GOTO Main_Loop
  70.       ENDCASE
  71.       CASE "S"                          ; S)ave
  72.      GOSUB Store
  73.      GOTO Main_Loop
  74.       ENDCASE
  75.       CASE "N"                          ; S)ave
  76.      IF FLAG(8)
  77.         GOSUB Store         ; Save on disk
  78.         SET FLAG(8) OFF
  79.         ENDIF
  80.      SET TRAN ON
  81.      GOTO Main_Loop
  82.       ENDCASE
  83.       CASE "F"                          ; S)ave
  84.      SET TRAN OFF
  85.      GOTO Main_Loop
  86.       ENDCASE
  87.    ENDSWITCH
  88. ;
  89. ;     Begin numeric entry
  90. ;
  91.    IF NOT NULL S0(1:3)            ; Disallow other special keys
  92.       SOUND 100,100
  93.       GOTO Main_Loop
  94.       ENDIF
  95.    GOSUB Enter                ; Enter #
  96.    GOTO Main_Loop            ; And continue
  97. ;
  98. ; ----- Page up (cycle backwards through possible values)
  99. ;
  100. PgUp:
  101.    DEC N99
  102.    IF LT N99 0
  103.       N99 = 3
  104.       ENDIF
  105.    GOSUB DispPage
  106.    GOTO Main_Loop
  107. ;
  108. ; ----- Page down (cycle forwards through possible values)
  109. ;
  110. PgDn:
  111.    INC N99
  112.    IF GT N99 3
  113.       N99 = 0
  114.       ENDIF
  115.    GOSUB DispPage
  116.    GOTO Main_Loop
  117. ;
  118. ; ----- Home (move to first line)
  119. ;
  120. Home:
  121.    N99 = 0
  122.    GOSUB DispPage
  123.    GOTO Main_Loop
  124. ;
  125. ; ----- End (Move to last line)
  126. ;
  127. End:
  128.    N99 = 3
  129.    GOSUB DispPage
  130.    GOTO Main_Loop
  131. ;
  132. ; ----- Subroutine Exit - terminate the process
  133. ;
  134. Exit:
  135.    IF FLAG(8)                ; If table modified
  136.       GOSUB Ask_Save            ; Ask if to save
  137.       ENDIF
  138.    DO                    ; CLose any open windows
  139.      WCLOSE
  140.      UNTIL FAILURE
  141.    EXIT
  142. ;
  143. ; ----- Subroutine: Enter a value
  144. ;    .. on entry S0 -> The first keystroke
  145. ;    .. S9 within this subroutine the field being constructed
  146. ;    .. N6 within this subroutine is an index to field being constructed
  147. ;
  148. Enter:
  149.    N6 = 0                ; Index to field being built
  150.    S9 = ""                              ; Clear field
  151.    UPPER S0                ; Make upper case
  152.    CTOI S0 N0                ; Easier comparison
  153.    IF NOT ((GE N0 48 and LE N0 57) or EQ N0 88) ; Allow 0-9 and 'x'
  154.       SOUND 100,100
  155.       RETURN
  156.       ENDIF
  157.    CURSOR N0,N1
  158.    INC N1
  159.    LOCATE N0,N1
  160.    GOTO Keyin
  161. ;
  162. ;    Accept another keypress
  163. ;
  164. Keypress:
  165.    KEYGET S0                ; Get more from keybd
  166. ;
  167. ;    Catch backspace (and equivalent cursor left) here
  168. ;
  169. Keyin:
  170.    IF STRCMP S0 "08" or STRCMP S0 "4B00"; Backspace or cursor left
  171.       IF GT N6 0
  172.      CURSOR N0,N1
  173.      ATSAY N0,N1 (default) "^H"
  174.      DEC N6
  175.      ENDIF
  176.       IF EQ N6 0
  177.      RETURN             ; Nop at this pt
  178.      ENDIF
  179.       GOTO Keypress
  180.       ENDIF
  181. ;
  182. ;    Catch carriage return (and equivalent space/tab) here
  183. ;
  184.    IF STRCMP S0 "0D" or STRCMP S0 " " or STRCMP S0 "09" ; cr, space, tab
  185.       IF EQ N6 0            ; Look for nothing done
  186.      RETURN             ; Empty field
  187.      ENDIF
  188.       GOTO End_Entry            ; Done - try to convert it
  189.       ENDIF
  190. ;
  191. ;    Other control keys abort entry
  192. ;
  193.    IF NOT NULL S0(1:3)            ; If a special key
  194.       GOTO Abort_Entry            ; Exit on special key
  195.       ENDIF
  196. ;
  197. ;    Filter only 0-9, a-f, and 'x' here
  198. ;
  199.    UPPER S0                ; Make upper case
  200.    CTOI S0 N0                ; Easier comparison
  201.    IF NOT ((GE N0 48 and LE N0 57) or (GE N0 65 and LE N0 70) or EQ N0 88)
  202.       SOUND 100,100
  203.       GOTO Keypress
  204.       ENDIF
  205. ;
  206. ;    Add the character to the string being constructed
  207. ;
  208.    CURSOR N0,N1
  209.    ATSAY N0,N1 (default) S0
  210.    INC N1
  211.    LOCATE N0,N1
  212.    S9(N6:N6) = S0            ; Add the key
  213.    INC N6                ; Add to index
  214.    GOTO Keypress            ; And continue
  215. ;
  216. ;    Abort entry and return to main
  217. ;
  218. Abort_Entry:
  219.    RETURN
  220. ;
  221. ;    Error in entry
  222. ;
  223. Entry_Error:
  224.    SOUND 400,100
  225.    RETURN
  226. ;
  227. ;    End of entry - catch empty field
  228. ;
  229. End_Entry:
  230.       IF EQ N6 0            ; EMpty field
  231.      RETURN
  232.      ENDIF
  233. ;
  234. ;    Convert a leading 'x' into '0x'
  235. ;
  236.       IF STRCMP S9(0:0) "X"             ; 'x' in col 0
  237.      S9 = "0"&S9                    ; Add an initial 0
  238.      ENDIF
  239. ;
  240. ;    Try to convert the char
  241. ;
  242.       ATOI S9 N0            ; Convert
  243.       IF ERROR or (LT N0 0 or GT N0 255)
  244.      GOTO Entry_Error        ; .. indicate error
  245.      ENDIF
  246. ;
  247. ;    Lookup the value obtained
  248. ;
  249.    GOSUB Get_Value            ; Using N0, get its translation into N1
  250.    S0 = "Char %03d (x%02x) currently translates to %03d (x%02x)"
  251.    STRFMT S1 S0 N0,N0 N1,N1        ; Construct prompt
  252. ;
  253. ;    Open a window for the entry of the translation
  254. ;
  255.    WOPEN 19,0, 22,78 (default) TenterXIT
  256.    ATSAY 20,2, (default) S1        ; D
  257.    ATSAY 21,2  (default) "New translation: "
  258.    ATSAY 22,28 (default) " Press ESC to cancel "
  259. ;
  260. ;    Ask for the translation
  261. ;
  262. Tenter:
  263.    ATGET 21,19 (default) 4 S0        ; Get new translation
  264. ;
  265. ;    Catch empty response (Tenter_ESC also clears S0)
  266. ;
  267.    IF NULL S0                ; EMpty field
  268.       WCLOSE                ; Drop window
  269.       RETURN
  270.       ENDIF
  271. ;
  272. ;    Convert a leading 'x' into '0x'
  273. ;
  274.    IF STRCMP S0(0:0) "X"                ; 'x' in col 0
  275.       S0 = "0"&S0                       ; Add an initial 0
  276.       ENDIF
  277. ;
  278. ;    Try to convert the char
  279. ;
  280.    ATOI S0 N1                ; Convert
  281.    IF ERROR or (LT N1 0 or GT N1 255)
  282.       SOUND 400,100
  283.       GOTO Tenter            ; .. Try again
  284.       ENDIF
  285. ;
  286. ;    We have a value (N0 translating into N1)
  287. ;
  288.    WCLOSE
  289.    SET FLAG(8) ON            ; Mark updated
  290.    GOSUB Set_Value
  291. ;
  292. ;    Redisplay the line or page modified
  293. ;
  294.    N3 = N0/128                ; N3  -> page #
  295.    IF GE N99 2                ; N99 -> incoming/outgoing
  296.       N3 = N3+2
  297.       ENDIF
  298.    IF NE N3 N99
  299.       N99 = N3                ; Set new page no
  300.       GOSUB DispPage            ; Display the new page
  301.    ELSE
  302.       N98 = N0 & 15            ; Make N98 = 0-15
  303.       GOSUB DispLine            ; Just redo the line (n98 = lineno)
  304.       ENDIF
  305.    RETURN
  306. ;
  307. ; ----- Escape during entry routine
  308. ;
  309. TenterXit:
  310.       S0 = ""                           ; Null input field
  311.       RETURN
  312. ;
  313. ; ----- Get a translation value
  314. ;    On entry N0 -> the char being translated
  315. ;    On exit  N1 <- the translation
  316. ;
  317. Get_Value:
  318.     N3 = N0/64        ; Mask string # (0-3)
  319.     IF GE N99 2        ; Decide incoming/outgoing
  320.        N3 = N3+4        ; Sel within incoming/outgoing tables
  321.        ENDIF
  322.     SWITCH N3        ; Switch on string # (0-7)
  323.       CASE 0
  324.         S0 = S10
  325.       ENDCASE
  326.       CASE 1
  327.         S0 = S11
  328.       ENDCASE
  329.       CASE 2
  330.         S0 = S12
  331.       ENDCASE
  332.       CASE 3
  333.         S0 = S13
  334.       ENDCASE
  335.       CASE 4
  336.         S0 = S14
  337.       ENDCASE
  338.       CASE 5
  339.         S0 = S15
  340.       ENDCASE
  341.       CASE 6
  342.         S0 = S16
  343.       ENDCASE
  344.       CASE 7
  345.         S0 = S17
  346.       ENDCASE
  347.     ENDSWITCH
  348.     CTOI S0(N0&63) N1
  349.     RETURN
  350. ;
  351. ; ----- Store a translation value
  352. ;    On entry N0 -> the